'use strict';

const Controller = require('egg').Controller;

class CollectController extends Controller {
    //关注
    async create() {
        let {ctx,service} = this;
        let {uid} = ctx.info;
        let {w_id} = ctx.request.body;
        if(w_id){
            try{
                await service.collect.create(w_id,uid);
                ctx.body = {
                    code:1,
                    msg:'收藏成功'
                }
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:e
                }
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数有误'
            }
        }
    }
    //取消收藏
    async destroy(){
        let {ctx,service} = this;
        let {id} = ctx.params;

        if(id){
            try{
                await service.collect.destroy(id);
                ctx.body = {
                    code:1,
                    msg:'取消收藏成功'
                }
            }catch(e){
                ctx.body = {
                    code:0,
                    msg:e
                }
            }
        }else{
            ctx.body = {
                code:2,
                msg:'参数有误'
            }
        }
    }
    //查询关注成员列表
    async index(){
        let {ctx,service} = this;
        let {uid} = ctx.info;

        let collectlist = await service.collect.index(uid);
        ctx.body = {
            code:1,
            data:collectlist
        }
    }
}

module.exports = CollectController;
